<?php
header('Content-Type: text/html; charset=utf-8');
function func_response($str = '')
{
    echo $str;exit;
}
function func_get($str){
    return isset($_GET[$str]) ? $_GET[$str] : '';
}
function func_request($str){
    return isset($_REQUEST[$str]) ? $_REQUEST[$str] : '';
}
function func_post($str){
    return isset($_POST[$str]) ? $_POST[$str] : '';
}
$t = func_request('t');
if ($t == '') {
    func_response('t不能为空error');
}
require('./db.php');
$add = func_request('add');
$del = func_request('del');
if (empty($add) && empty($del)) { 
    $sql = "select n from mails where t='{$t}'";
    $rs = Database::query($sql);
	if(empty($rs)) {
		func_response('当前{$t}无数据');
	}
    foreach ($rs as $item) {
        echo $item['n'];echo "\n";
    }
}
if(!empty($add)) {
$sql = "SELECT * FROM `mails` where `t`='{$t}' and `n`='{$add}' LIMIT 0, 1 ";
    $rs = Database::query($sql);
    if(!empty($rs)) {
        func_response('已有该邮箱error');
    }
    $sql = "INSERT INTO mails(t,n,d)VALUES ('{$t}','{$add}',now());";
    if(Database::change($sql) > 0) {
        func_response('插入success');
    } else {
        func_response('插入error');
    }
}
if(!empty($del)) {
    $sql = "DELETE FROM `mails` WHERE t='{$t}' and n='{$del}'";
    if(Database::change($sql) > 0) {
        func_response('删除success');
    } else {
        func_response('删除error');
    }
}